<?
    require_once("mvc/action/ActionForm.php");
    require_once("mvc/action/ActionMessage.php");
    require_once("mvc/action/ActionMessages.php");

    require_once("cms/user/om/User.php");


    class BaseUserForm extends ActionForm {

        protected $user;
        protected $password2;
        protected $roles;

        public function __construct() {
            $this->user = new User();
            $this->password2 = null;
            $this->roles = array();
        }

        public function getUser() {
            return $this->user;
        }

        public function setUser(User $user) {
            $this->user = $user;
        }

        public function getPassword2() {
            return $this->password2;
        }

        public function setPassword2($password2) {
            $this->password2 = $password2;
        }

        public function getRoles() {
            return $this->roles;
        }

        public function setRoles($roles) {
            $this->roles = $roles;
        }

        public function validate() {

            $errors = new ActionMessages();

            if(is_null($this->getUser()->getUsername()) || strlen($this->getUser()->getUsername()) == 0)
                $errors->add("user->username",
                    new ActionMessage("errors.required", true, new ActionMessage("prompt.username", true)));


            if(!is_null($this->getUser()->getUsername()) && strlen($this->getUser()->getUsername()) > 0 && strlen($this->getUser()->getUsername()) < 3)
                $errors->add("user->username",
                    new ActionMessage("errors.minlength", true, array(
                        new ActionMessage("prompt.username", true),
                        new ActionMessage("3", false))));

            if(!is_null($this->getUser()->getUsername()) && strlen($this->getUser()->getUsername()) > 0 && strlen($this->getUser()->getUsername()) > 32)
                $errors->add("user->username",
                    new ActionMessage("errors.maxlength", true, array(
                        new ActionMessage("prompt.username", true),
                        new ActionMessage("32", false))));


            if(!is_null($this->getUser()->getPassword()) && strlen($this->getUser()->getPassword()) > 0 && strlen($this->getUser()->getPassword()) < 3)
                $errors->add("user->password",
                    new ActionMessage("errors.minlength", true, array(
                        new ActionMessage("prompt.password", true),
                        new ActionMessage("3", false))));

            if(!is_null($this->getUser()->getPassword()) && strlen($this->getUser()->getPassword()) > 0 && strlen($this->getUser()->getPassword()) > 32)
                $errors->add("user->password",
                    new ActionMessage("errors.maxlength", true, array(
                        new ActionMessage("prompt.password", true),
                        new ActionMessage("32", false))));


            return $errors;
        }

    }
?>